

#import "Api.h"
#import "EnvHeader.h"

@implementation Api

+(void)apiLogin:(NSString*)moblie password:(NSString*)password handler:(LoginHandler)handler {
    NSString *url = @"v1/account/login";
    NSDictionary *param = @{@"mobile": moblie,
                            @"password": password};
    [self POST:url parameters:param responseClass:[ResponseLogin class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseLogin *results = (ResponseLogin *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

+(void)apiUserInfoHandler:(UserInfoHandler)handler {
    NSString *url = @"fishery/fishery/v1/act/userInfo";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token
                            };
    [self POST:url parameters:param responseClass:[ResponseUserInfo class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseUserInfo *results = (ResponseUserInfo *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

+(void)apiFisheryIndex:(FisherIndexHandler)handler {
    NSString *url = @"fishery/fishery/v1/act/fisheryIndex";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token
                            };
    [self POST:url parameters:param responseClass:[ResponseFisherIndex class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseFisherIndex *results = (ResponseFisherIndex *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

+(void)apiMyFishHandler:(MyFishHandler)handler {
    NSString *url = @"v1/myfish/index";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token
                            };
    [self POST:url parameters:param responseClass:[ResponseMyFishList class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseMyFishList *results = (ResponseMyFishList *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

+(void)apiOceanHandler:(OceanHandler)handler {
    NSString *url = @"adventure/advengo/v1/act/ocean";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token
                            };
    [self POST:url parameters:param responseClass:[ResponseOcean class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseOcean *results = (ResponseOcean *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

+(void)apiFishDetail:(NSNumber*)level type:(NSNumber*)type career:(NSNumber*)career handler:(FishDetailHandler)handler {
    NSString *url = @"v1/myfish/groupList";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            @"level":FORMAT(@"%@",level),
                            @"type":FORMAT(@"%@",type),
                            @"career":FORMAT(@"%@",career)
                            };
    [self POST:url parameters:param responseClass:[ResponseFishDetail class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseFishDetail *results = (ResponseFishDetail *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

+(void)apiEvolveAttr:(NSNumber*)fish_id career:(NSNumber*)career handler:(EvolveAttrHandler)handler {
    NSString *url = @"v1/myfish/getEvolveAttr";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            @"id":FORMAT(@"%@",fish_id),
                            @"career":FORMAT(@"%@",career)
                            };
    [self POST:url parameters:param responseClass:[ResponseEvolveAttr class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseEvolveAttr *results = (ResponseEvolveAttr *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

// 探索
+(void)apiAdventure:(NSNumber*)ocean_id handler:(GoAdventureHandler)handler
{
    NSString *url = @"adventure/advengo/v1/act/go_adventure";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            @"ocean_id": FORMAT(@"%@",ocean_id),
                            };
    [self POST:url parameters:param responseClass:[ResponseGoAdventure class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseGoAdventure *results = (ResponseGoAdventure *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

// 自动选择鱼苗 - id
+(void)apiAutoSelect:(NSNumber*)fish_id handler:(FishDetailHandler)handler {
    NSString *url = @"v1/myfish/autoSelectDevourTarget";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            @"fish_id": FORMAT(@"%@",fish_id),
                            };
    [self POST:url parameters:param responseClass:[ResponseFishDetail class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseFishDetail *results = (ResponseFishDetail *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

// 吞噬
+(void)apiEatFish:(NSNumber*)fish_id target_fishId:(NSNumber*)target_fishId count:(NSNumber*)count handler:(BaseHandler)handler {
    NSString *url = @"v1/myfish/devour";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            @"fish_id": FORMAT(@"%@",fish_id),
                            };
    NSMutableDictionary *mDic = [[NSMutableDictionary alloc]initWithDictionary:param];
    NSInteger total = [count integerValue];
    for (int i = 0 ; i < total; i++) {
        NSString *key = FORMAT(@"target_fish_ids[%d]",i);
        mDic[key] = FORMAT(@"%@",target_fishId);
    }
    [self POST:url parameters:mDic responseClass:[Response class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            Response *results = (Response *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}
// 进化接口
+(void)apiJinghua:(NSNumber*)fish_id handler:(BaseHandler)handler
{
    NSString *url = @"v1/myfish/evolve";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            @"id": FORMAT(@"%@",fish_id)
                            };
    [self POST:url parameters:param responseClass:[Response class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            Response *results = (Response *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

// 查询购买
+(void)apiBuyCheck:(BuyCheckHandler)handler
{
    NSString *url = @"adventure/advengo/v1/act/buytili";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            @"type": @"1"
                            };
    [self POST:url parameters:param responseClass:[ResponseBuyCheck class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseBuyCheck *results = (ResponseBuyCheck *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

// 购买ETH
+(void)apiBuy:(BaseHandler)handler
{
    NSString *url = @"adventure/advengo/v1/act/buytili";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            };
    [self POST:url parameters:param responseClass:[ResponseBuyCheck class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseBuyCheck *results = (ResponseBuyCheck *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

// 购买鱼苗
+(void)apiBuyMiniFish:(NSNumber*)countryId fisheryId:(NSNumber*)fisheryId count:(NSNumber*)count handler:(BaseHandler)handler {
    NSString *url = @"fishery/fishery/v1/act/purchase";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            
                            @"countryId": FORMAT(@"%@",countryId),
                            @"fisheryId": FORMAT(@"%@",fisheryId),
                            @"buyNum": FORMAT(@"%@",count),
                            
                            };
    [self POST:url parameters:param responseClass:[Response class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            Response *results = (Response *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

+(void)apiMyMiniFishNum:(NSNumber*)fisheryId handler:(MyFishHandler)handler
{
    NSString *url = @"fishery/fishery/v1/act/buyIndex";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            @"fisheryId": FORMAT(@"%@",fisheryId)
                            };
    [self POST:url parameters:param responseClass:[ResponseMyFishList class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseMyFishList *results = (ResponseMyFishList *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

// 渔场信息
+(void)apiFishMap:(FishMapHandler)handler
{
    NSString *url = @"v1/Fishing/fishingMap";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            };
    [self POST:url parameters:param responseClass:[ResponseFishMap class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseFishMap *results = (ResponseFishMap *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

// 钓鱼
+(void)apiFisingWithSucc:(NSNumber*)type mapid:(NSNumber*)mapid handler:(FishAwardHandler)handler
{
    NSString *url = @"v1/Fishing/fishing";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            @"type": FORMAT(@"%@",type),
                            @"map_id": FORMAT(@"%@",mapid)
                            };
    [self POST:url parameters:param responseClass:[ResponseFishAward class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseFishAward *results = (ResponseFishAward *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

+(void)apiOfferListWithHandler:(OfferIndexHandler)handler
{
    NSString *url = @"v1/Offer/offer_index";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            };
    [self POST:url parameters:param responseClass:[ResponseOfferIndex class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseOfferIndex *results = (ResponseOfferIndex *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}

// 献祭接口
+(void)apiOfferGoWithFishId:(NSNumber*)fishId fishLevel:(NSNumber*)level handler:(OfferGoHandler)handler
{
    NSString *url = @"v1/Offer/offer_go";
    Token *token = [Token loadCache];
    NSDictionary *param = @{@"uid": FORMAT(@"%td",token.uid),
                            @"lang": @"zh",
                            @"token": token.token,
                            @"fish_id": fishId,
                            @"level": level,
                            @"type": @(2),
                            };
    [self POST:url parameters:param responseClass:[ResponseOffGo class] handler:^(id response, NSError *error) {
        if (error) {
            BLOCK_EXEC(handler,nil,error);
        }
        else {
            ResponseOffGo *results = (ResponseOffGo *)response;
            BLOCK_EXEC(handler,results,error);
        }
    }];
}
@end
